<%--
  Created by IntelliJ IDEA.
  User: RuoLi
  Date: 2022/12/12
  Time: 21:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
    <script src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/base.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/iconfont.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/reg.css">
</head>
<body>
<div id="ajax-hook"></div>
<div class="wrap">
    <div class="wpn">
        <div class="form-data pos">
            <img src="<%=request.getContextPath()%>/img/logo.png" class="head-logo">
            <form>
                <p class="p-input pos">
                    <label for="UserMail">QQ邮箱</label>
                    <input type="email" id="UserMail">
                </p>
                <p class="p-input pos " id="pwd">
                    <label for="UserPassword1">输入密码</label>
                    <input type="password" id="UserPassword1">
                    <span class="tel-warn pwd-err hide"><em></em><i class="icon-warn"
                                                                    style="margin-left: 5px"></i></span>
                </p>
                <p class="p-input pos " id="confirmpwd">
                    <label for="UserPassword2">确认密码</label>
                    <input type="password" id="UserPassword2">
                    <span class="tel-warn confirmpwd-err hide"><em></em><i class="icon-warn"
                                                                           style="margin-left: 5px"></i></span>
                </p>
                <p class="p-input pos" id="sendcode">
                    <label for="veri-code">输入验证码</label>
                    <input type="text" id="veri-code">
                    <a href="javascript:;" class="send">发送验证码</a>
                    <span class="time hide"><em>120</em>s</span>
                    <span class="error hide"><em></em><i class="icon-warn" style="margin-left: 5px"></i></span>
                </p>
            </form>
            <button class="lang-btn register">注册激活</button>
            <div class="bottom-info">已有账号，<a href="index.jsp">马上登录</a></div>
        </div>
    </div>
</div>
</body>
<script>
    $(".send").click(function () {
        //邮箱正则表达式
        var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
        var pwd1 = $("#UserPassword1").val()
        var pwd2 = $("#UserPassword2").val()
        //验证UserMail
        if (!reg.test($("#UserMail").val())) {
            alert("邮箱格式不正确");
            return;
        }
        //密码长度不低于6
        if (pwd1.length < 6 && pwd2.length < 6) {
            alert("密码长度不低于6")
            //检查密码两次输入是否一样
            return;
        }
        if (pwd1 !== pwd2) {
            alert("输入密码不一致，请重新输入！")
            //清空密码框
            $("#UserPassword1").val("")
            $("#UserPassword2").val("")
            return;
        }
        $.ajax({
            type: "get",
            url: "User/UserRegister",
            data: {
                UserMail: $("#UserMail").val(),
                UserPassword: $("#UserPassword1").val()
            },
            success: function (data) {
                alert("验证码发送成功，请在邮箱注意查收！")
            },
            error: function () {
                alert("发送失败")
            }
        })
    })
    $(".register").click(function () {
        $.ajax({
            type: "post",
            url: "User/UserRegister",
            data: {
                UserMail: $("#UserMail").val(),
                UserPassword: $("#UserPassword1").val(),
                code: $("#veri-code").val()
            },
            success: function (data) {
                if (data == 1) {
                    alert("账号激活成功")
                    window.location.href = "index.jsp"
                } else if (data == -1) {
                    alert("检查验证码是否有误")
                } else {
                    alert("程序未响应,重新注册")
                }

            },
            error: function () {
                alert("注册失败")
            }
        })
    })
</script>
</html>
